package com.xiaochong.tir.apiservice.component;

import akka.actor.UntypedActor;
import com.alibaba.fastjson.JSON;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.tir.apiservice.util.SpringContextUtil;
import com.xiaochong.tir.common.data.hbasepo.CmcCurrencyInfo;
import com.xiaochong.tir.common.data.hbasepo.DiagnosisPressureSupporte;
import com.xiaochong.tir.common.data.hbasepo.LongShortTrend;
import com.xiaochong.tir.common.util.LogTraceKeysUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by wujiaxing on 2018/5/7.
 */
public class AkkaLongShortTrend extends UntypedActor {


    private CmcDataCalculateComponent cmcDataCalculateComponent =
            (CmcDataCalculateComponent) SpringContextUtil.getBean("cmcDataCalculateComponent");

    @Override
    public void onReceive(Object o) {
        LogTrace.beginTrace("多空趋势计算");
        Object o1 = ((Object[]) o)[0];
        Map<String, CmcCurrencyInfo> cmcInfoMap = (Map<String, CmcCurrencyInfo>) o1;
        LogTrace.info(LogTraceKeysUtils.AKKA_LONG_SHORT_TREND_TITLE, LogTraceKeysUtils.DATA,"多空趋势计算开始");

        try{
            List<LongShortTrend> longShortTrends = cmcDataCalculateComponent.calculateLongShortTrend(cmcInfoMap);
            LogTrace.info(LogTraceKeysUtils.AKKA_LONG_SHORT_TREND_TITLE, LogTraceKeysUtils.DATA, "多空趋势计算完成");
            if(longShortTrends!=null && longShortTrends.size()>0){
                cmcDataCalculateComponent.saveLongShortTrend(longShortTrends);
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error(e.getMessage(), e);
        }
        LogTrace.endTrace();
    }
}
